package com.g4m.baselib.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;

/**
 * Created on 2020-01-01
 * <p>Copyright 2008-2020 snsndk.com</p>
 *
 *
 */
@Setter
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseObjectData {
    /**
     * 当前页条数
     */
    private Integer count = 0;
    /**
     * 总条数
     */
    private Integer total = 0;
    /**
     * 当前页
     */
    private Integer page = 1;

    /**
     * 每页条数
     */
    private Integer limit = 20;

    /**
     * 总页数
     */
    private Integer totalPage = 0;

    /**
     * 是否还有更多数据
     */
    private Integer hasMore = 0;

    /**
     * 游标
     */
    private Long cursor;

    /**
     * 数据列表集合
     */
    private Object list;

    public ResponseObjectData() {

    }

    public ResponseObjectData(Integer total, Integer page, Integer limit, Integer count, Object list) {
        this.total = total;
        this.page = page;
        this.limit = limit;
        this.count = count;
        this.list = list;
        this.totalPage = (int) Math.ceil((double) total / (double) getLimit());
        this.hasMore = totalPage > page ? 1 : 0;
    }

    public Integer getPage() {
        if (page < 1) {
            return 1;
        }
        return page;
    }

    public Integer getLimit() {
        if (limit < 1) {
            return 1;
        }
        return limit;
    }

}
